import type { Directive } from 'vue'
export const permission: Directive = {
  mounted(el, binding) {
    //value按钮上的权限
    const { value } = binding

    // document.title = value || '团购'
    // document.title = " "
  }
}

// 自定义指令防止按钮重复点击 v-preventReClick
export const preventReClick: Directive = {
  mounted(el, binding) {
    let throttleTime = binding.value // 节流时间
    if (!throttleTime) {
      // 用户若不设置节流时间，则默认2s
      throttleTime = 3000
    }
    let cbFun: any
    el.addEventListener(
      'click',
      (event: any) => {
        if (!cbFun) {
          // 第一次执行
          cbFun = setTimeout(() => {
            cbFun = null
          }, throttleTime)
        } else {
          event && event.stopImmediatePropagation()
        }
      },
      true
    )
  }
}



// 自定义指令防止按钮重复 v-preventReTouch
export const preventReTouch: Directive = {
  mounted(el, binding) {
    let throttleTime = binding.value // 节流时间
    if (!throttleTime) {
      // 用户若不设置节流时间，则默认2s
      throttleTime = 3000
    }
    let cbFun: any
    el.addEventListener(
      'mouseenter',
      (event: any) => {
        
        if (!cbFun) {
          // 第一次执行
          cbFun = setTimeout(() => {
            cbFun = null
          }, throttleTime)
        } else {
          event && event.stopImmediatePropagation()
        }
      },
      true
    )
  }
}
